package com.hjx.misc;

import com.alibaba.fastjson.JSON;
import org.apache.commons.collections.CollectionUtils;
import org.junit.Assert;
import org.junit.Test;

import java.util.ArrayList;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class CollectionCompare {

    @Test
    public void compareCollection(){

        ArrayList<String> list1 = new ArrayList<String>() {{
            add("1");
            add("2");
            add("3");
        }};
        ArrayList<String> list2 = new ArrayList<String>() {{
            add("3");
            add("2");
            add("1");
        }};
        ArrayList<String> list3 = new ArrayList<String>() {{
            add("3");
            add("2");
            add("13");
        }};
        Assert.assertTrue(CollectionUtils.isEqualCollection(list1, list2));

        Assert.assertTrue(CollectionUtils.isEqualCollection(list1, list3));
    }

    @Test
    public void testStream(){
        System.out.println(Stream.of("a", "c", "b").sorted().collect(Collectors.toMap(new Function<String, Object>() {
            @Override
            public Object apply(String s) {
                return s + "1";
            }
        }, new Function<String, Object>() {
            @Override
            public Object apply(String s) {
                return s;
            }
        })));
    }

    @Test
    public void split(){
        String trace = "142,314@118,328@143,314@168,332@193,314@218,321@243,314@268,331@293,314@318,318@343,314@360,290@359,315@377,340@359,365@365,390@359,415@360,440@359,465@379,490@359,515@383,533@358,531@333,542@308,531@283,536@258,531@233,534@208,531@183,538@158,531@146,507@142,532@147,557@142,582@162,607@142,632@147,657@142,682@158,707@142,732@118,764@143,748@168,749@193,748@218,751@243,748@268,762@293,748@318,751@343,748@335,772@360,747@385,722@410,697@435,672@460,647@485,622@510,597@535,572@560,547@588,507@576,532@580,557@576,582@578,607@576,632@584,657@576,682@580,707@576,732";
        System.out.println(trace.length());
        for (String x_y:
             trace.split("@")) {
            System.out.println(x_y);
        }
    }
}
